// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
namespace Microsoft.Xrm.Sdk
{
	using System;
	using System.Collections.Generic;
    using System.Runtime.Serialization;
	using Microsoft.Xrm.Sdk.Temporary;

	/// <summary>
	/// AliasedValue used by CRM to return aggregate, group by and aliased values from a query
	/// </summary>
	[KnownType("GetKnownAliasedValueTypes")]
	[DataContract(Name = "AliasedValue", Namespace = XmlNamespaces.V5.Contracts)]
	public sealed class AliasedValue : IExtensibleDataObject
	{
		/// <summary>
		/// Name of the attribute on which the aggregate, group by or select was performed.
		/// </summary>
		[DataMember]
		public string AttributeLogicalName
		{
			get;
			internal set;
		}

		/// <summary>
		/// Name of entity the attribute belongs to.
		/// </summary>
		[DataMember]
		public String EntityLogicalName
		{
			get;
			internal set;
		}

		/// <summary>
		/// Value returned by the query.
		/// </summary>
		[DataMember]
		public object Value
		{
			get;
			internal set;
		}

		#region private members
		internal static IEnumerable<Type> GetKnownAliasedValueTypes()
		{
			List<Type> knownTypes = new List<Type>();
			// add base attribute types.
			KnownTypesProvider.AddKnownAttributeTypes(knownTypes);
			return knownTypes;
		}
		#endregion

		#region IExtensibleDataObject Implementation
		private ExtensionDataObject ExtensionDataObject;
		public ExtensionDataObject ExtensionData
		{
			get
			{
				return ExtensionDataObject;
			}
			set
			{
				ExtensionDataObject = value;
			}
		}
		#endregion IExtensibleDataObject Implementation
	}
}

